#include "StdAfx.h"
#include "Interpolator.h"

CIDWInterpolator::CIDWInterpolator()
	: pProvider(NULL)
{
}

CIDWInterpolator::~CIDWInterpolator()
{
}

void CIDWInterpolator::Initialize(IDataProvider* _pProvider)
{
	pProvider = _pProvider;
}

float CIDWInterpolator::Interpolate(void* pos)
{
	UINT uiCount = pProvider->GetCount();
	double dNume = 0, dDeno = 0;

	for(UINT i = 0; i < uiCount; ++i)
	{
		float fDist = pProvider->GetDistance(i, pos);
		float fData = pProvider->GetData(i);
		if(fDist < __EPSILON__)return fData;

		dNume += fData * 1.0 / (fDist * fDist);
		dDeno += 1.0 / (fDist * fDist);
	}

	return (float)(dNume / dDeno);
}